package network;

import java.io.IOException;
import java.net.SocketException;
import java.util.HashMap;
import java.util.Map;

/**
 * @version 1.8
 * @Author Djx_hmbb
 * @Date 2023/10/7 15:08
 * @注释:
 */
public class UdpDictServer extends UdpEchoServer{
    private Map<String,String >dict = new HashMap<>();

    public UdpDictServer(int port) throws SocketException {
        super(port);
        //给这个dict设置内容
        dict.put("cat","小猫");
        dict.put("dog","小狗");
        dict.put("fuck","wocao");
        //可以设置无限多个键值对
    }

    @Override
    public String process(String request) {
        return dict.getOrDefault(request,"当前单词没有查到结果！");
    }

    public static void main(String[] args) throws IOException {
        UdpDictServer dict = new UdpDictServer(8080);
        dict.start();
    }
}
